"""
数据查询验证
"""
import pandas as pd
from tools.utils import loc_collection, loc_zq_collection


def to_df(find_dic):
    return pd.DataFrame(find_dic['value'], index=find_dic['t'], columns=find_dic['columns'])


def dic_to_txt(dic):
    with open('data.txt', 'w') as f:
        for k, v in dic.items():
            f.write(str(k) + 'ssssss' + str(v) + '\n')


def txt_to_dic(path):
    dic = {}
    with open(path, 'r') as f:
        for line in f.readlines():
            print(line)
            k, v = line.split('ssssss')
            dic[k] = v
    return dic


if __name__ == "__main__":
    import numpy as np
    coll_ = loc_collection('to_it', 'goods')
    # dic = {'mode': '现货', 'chinese_name': '甲醇', 'seasonal': False}
    dic = {
        # 'chinese_name': '铁矿石',
        'mode': '期货', 'freq': '日'}
    data = list(coll_.find(dic))
    new_data = {}
    for v in data:
        chinese = v['chinese_name']
        t = v['t'][-9:]
        value = [s[0] for s in v['value']]
        val = value[-9:]
        val_ = [f'{s:.1f}' for s in val]
        new_data[chinese] = dict(zip(t, val_))

    dic_to_txt(new_data)

    cc = txt_to_dic("data.txt")